#pragma once

#include "DXAMLCommon.h"
#include "CValue.h"
#include "XamlTypeToken.h"
#include "CDependencyObject.h"
#include "XamlBitSet.h"






struct XamlQualifiedObject
{
public:
	enum QualifiedObjectFlags
	{
		qofNone = 0x0,
		qofBoxed = 0x1,
		qofString = 0x2,
		qofContainedDORequiresRelease = 0x8,
		qofHasPeggedManagedPeer = 0x10,
	};
private: 
	struct XamlTypeToken m_typeToken;
	XamlBitSet<enum XamlQualifiedObject::QualifiedObjectFlags> m_flags;
	CValue m_value;

private: 
	HRESULT             SetInternalData(const struct XamlTypeToken & inTypeToken, const CValue & inValue, const XamlBitSet<enum XamlQualifiedObject::QualifiedObjectFlags> & inFlags, XBOOL bUseCValueCopy, XBOOL bTakeOwnership);
public: 
	XamlQualifiedObject(const struct XamlQualifiedObject & rhs);
	XamlQualifiedObject(struct XamlTypeToken typeToken);
	XamlQualifiedObject();
	static HRESULT      Create(const struct XamlTypeToken & typeToken, CDependencyObject * pDO, xshared_ptr<XamlQualifiedObject> & outQO);
	static HRESULT      CreateNoAddRef(const struct XamlTypeToken & typeToken, CDependencyObject * pDO, xshared_ptr<XamlQualifiedObject> & outQO);
	struct XamlQualifiedObject & operator=(const struct XamlQualifiedObject & rhs);
	~XamlQualifiedObject();
	XBOOL               IsEmpty();
	void                Clear();
	XBOOL               GetIsStringValue();
	XBOOL               GetIsBoxed();
	XBOOL               GetContainedDORequiredRelease();
	XBOOL               GetHasPeggedManagedPeer();
	void                SetHasPeggedManagedPeer();
	CValue &            GetValue();
	const CValue &      GetValue() const;
	CValue *            GetCValuePtr();
	const struct XamlTypeToken & GetTypeToken();
	const XamlBitSet<enum XamlQualifiedObject::QualifiedObjectFlags> & GetFlags();
	void                SetTypeToken(struct XamlTypeToken inToken);
	CDependencyObject * GetDependencyObject();
	HRESULT             GetCopyAsString(xshared_ptr<CXString> & outssString);
	HRESULT             ConvertForManaged(struct XamlQualifiedObject & outManagedQualifiedObject);
	HRESULT             SetDependencyObject(CDependencyObject * pdo);
	void                SetDependencyObjectNoAddRef(CDependencyObject * pdo);
	HRESULT             SetValue(const struct XamlTypeToken & inTypeToken, const CValue & rValue, XBOOL bUseCValueCopy, XBOOL bTakeOwnership);
	HRESULT             SetValue(const CValue & rValue);
	void                SetFreeValuePointerOnCValueIfNeeded(XBOOL bShouldFreeValuePointer);
	void                ClearHasPeggedManagedPeer();
private: 
	void                Reset();
	XBOOL               ShouldSetPegFlagDuringSetValue(const CValue & rValue);

};
